#include "OriginPCH.h"
#include "Renderer.h"
#include "Platform/OpenGL/OpenGLShader.h"

namespace Origin
{
    Renderer::SceneData* Renderer::_sceneData = new Renderer::SceneData;

    void Renderer::Init()
    {
        RenderCommand::Init();
    }

    void Renderer::BeginScene(OrthographicCamera& camera)
    {
        _sceneData->viewProjMatrix = camera.GetViewProjectionMatrix();
    }

    void Renderer::EndScene()
    {

    }

    void Renderer::Submit(const std::shared_ptr<Shader>& shader, 
        const std::shared_ptr<VertexArray>& vertexArray,
        const glm::mat4& transform = glm::mat4(1.0f))
    {
        shader->Bind();
        std::dynamic_pointer_cast<OpenGLShader>(shader)->UploadUniformMat4("u_ViewProjection", _sceneData->viewProjMatrix);
        std::dynamic_pointer_cast<OpenGLShader>(shader)->UploadUniformMat4("u_Transform", transform);

        vertexArray->Bind();
        RenderCommand::DrawIndexed(vertexArray);
    }
}